#define _CRT_SECURE_NO_WARNINGS 1
#include<string>
#include<iostream>
using namespace std;
class Solution2 {
public:
    bool isUnique(string astr) {
        int a = 0;
        for (int i = 0; i < astr.size(); i++)
        {
            if ((a >> (astr[i] - 'a')) && 1 == 1)
            {
                return false;
            }
            else
            {
                a |= 1 << (astr[i] - 'a');
            }
        }
        return true;
    }
};

#include<vector>
class Solution3 {
public:
    int missingNumber(vector<int>& nums) {
        int ret = 0;
        for (int i = 0; i < nums.size(); i++)
        {
            ret ^= nums[i];
        }
        for (int i = 1; i <= nums.size(); i++)
        {
            ret ^= i;
        }
        return ret;
    }
};

class Solution4 {
public:
    int getSum(int a, int b)
    {
        int i = a ^ b;
        int carry = (a & b) << 1;
        while (carry)
        {
            int j = i ^ carry;
            carry = (i & carry) << 1;
            i = j;

        }
        return i;
    }
};

class Solution1 {
public:
    int singleNumber(vector<int>& nums) {
        int ret = 0;
        for (int i = 0; i < 32; i++)
        {
            int sum = 0;
            for (auto x : nums)
            {
                
                if (((x >> i) & 1) == 1)
                {
                    sum++;
                }
            }
            sum %= 2;
            if (sum == 1)
            {
                ret |= 1 << i;
            }
        }
        return ret;
        
    }
};

class Solution5 {
public:
    vector<int> missingTwo(vector<int>& nums) {
        int tmp = 0;
        for (int i = 0; i < nums.size(); i++)
        {
            tmp ^= nums[i];
        }
        for (int i = 1; i <= nums.size() + 2; i++)
        {
            tmp ^= i;
        }
        int diff = 0;
        for (int i = 0; i < 32; i++)
        {
            if (((tmp >> i) & 1) == 1)
                diff = i;
            break;
        }
        int a = 0, b = 0;
        for (int i = 0; i < nums.size(); i++)
        {
            if (((nums[i] >> diff) & 1) == 1) b ^= nums[i];
            else a ^= nums[i];
        }
        for (int i = 1; i <= nums.size() + 2; i++)
        {
            if (((i >> diff) & 1) == 1) b ^= i;
            else a ^= i;
        }
        return { a,b };
    }
};

int main()
{
    vector<int> nums = { 0,1,99 ,0,1 };
    Solution1 s;
    cout << s.singleNumber(nums);
    
    return 0;
}